<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
  <h1>异步请求测试</h1><!--异步请求时click点击事件时调用方法发请求,所以无需form表单提交请求-->
  <input type="text" placeholder="名字" v-model="name">
  <input type="text" placeholder="年龄" v-model="age">
  <input type="button" value="异步get请求" @click="f1()">
  <hr>
  <input type="text" placeholder="标题" v-model="product.title">
  <input type="text" placeholder="价格" v-model="product.price">
  <input type="text" placeholder="库存" v-model="product.num">
  <input type="button" value="发出post异步请求" @click="f2()">
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
   let v = new Vue({
        el: "body>div",
        data:{
          name:"",
          age:"",
          product:{
            title:"",
            price:"",
            num:""
          }

        },
       methods:{
         //发出异步的get请求/helloAxios?name=张三&age=18
         f1(){
           axios.get("/helloAxios?name="+v.name+"&age="+v.age).then(function (response){
             alert(response.data);
           })
         },

         f2(){
           //发出异步的post请求
           axios.post("/postAxios",v.product).then(function (response){
             alert(response.data);
           })

         }

       }
    })
</script>

</body>
</html>